<template>
  <div class="navbar">
    <div class="left">
      <span class="logo">vue3-admin-template</span>
    </div>
    <div class="right">
      <el-dropdown>
        <span class="el-dropdown-link">
          {{ authStore.userInfo?.username || '用户' }}
          <i class="el-icon-arrow-down"></i>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup>
import { useAuthStore } from '@/store/auth'
import { useRouter } from 'vue-router'

const authStore = useAuthStore()
const router = useRouter()

const logout = async () => {
  await authStore.logout()
  router.push('/login')
}
</script>

<style scoped>
.navbar {
  height: 50px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid #eee;
}
.logo {
  color: #fff;
  font-weight: bold;
}
.el-dropdown-link {
  color: #eee;
  font-weight: bold;
}
</style>
